package 笔试.字节;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/8/29-8:55
 * @version:1.0
 * @function:System.out.println(String.format("%.2f", max/2));
 */
public class Main2101 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int[][] group = new int[m][3];
        int[][] skill = new int[n][3];
        int[] res = new int[n];
        for (int i = 0; i < group.length; i++) {
            group[i][0] = scanner.nextInt();
            group[i][1] = scanner.nextInt();
            group[i][2] = scanner.nextInt();
        }
        for (int i = 0; i < skill.length; i++) {
            skill[i][0] = scanner.nextInt();
            skill[i][1] = scanner.nextInt();
            skill[i][2] = scanner.nextInt();
        }
        int a = 0, b = 0, c = 0;
        for (int i = 0; i < m; i++) {
            a += group[i][0];
            b += group[i][1];
            c += group[i][2];
            for (int j = 0; j < n; j++) {
                if (res[j] <= 0 && a >= skill[j][0] && b >= skill[j][1] && c >= skill[j][2]) res[j] = i + 1;
                else if (res[j] <= 0) res[j] = -1; // 问题关键
            }
        }
        System.out.println(Arrays.toString(res));
    }
}
